package com.chuanyang.driverh.utils.net;

import android.content.Context;

import com.chuanyang.driverh.bean.EditCarTeamData;
import com.chuanyang.driverh.bean.Waybill;
import com.chuanyang.driverh.utils.ConstUtil;
import com.chuanyang.driverh.utils.JsonUtil;
import com.chuanyang.driverh.utils.NetUtil;
import com.chuanyang.driverh.utils.PrintUtil;
import com.chuanyang.driverh.utils.SharedPrefUtil;
import com.chuanyang.driverh.utils.eventbus.ErrorEvent;
import com.zhy.http.okhttp.OkHttpUtils;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import de.greenrobot.event.EventBus;
import okhttp3.MediaType;

/**
 * Created by xupeixian on 2017/2/9.
 */

public class MyHttpUtil {
    public static void getCode(Context context,Map<String, String> params, MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/user/getValidateCode";
        get(context,url, params, callback);
    }
    public static void login(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/user/signIn";
        post(context,url, params,callback);
    }
    public static void registerOrChangePwd(Context context,int type,Map<String, String> params, MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL +(type==1? "info/user/regUser":"info/user/updatePwdByVCode");
        post(context,url, params, callback);
    }
    //接口停用
 /*   public static void getUserInfo(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/user/select";
        post(context,url, params,callback);
    }*/

    public static void getLines(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/driverline/DriverId";
        post(context,url, params,callback);
    }
    public static void deleteLines(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/driverline/delete";
        post(context,url, params,callback);
    }

    public static void changeUserImage(Context context,File file,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/user/updateUserImage";
        postFile(context,url, file,callback);
    }

    public static void updateUser(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/driver/updateUser";
        post(context,url, params,callback);
    }

    public static void selectUser(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/driver/selectUser";
        post(context,url, params,callback);
    }
    public static void selectLgCompanyByName(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/lgCompany/selectLgCompanyByName";
        post(context,url, params,callback);
    }
    public static void getAccountById(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/account/getAccountById";
        post(context,url, params,callback);
    }
    public static void deleteBankCard(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/bankCard/delete";
        post(context,url, params,callback);
    }
    public static void getBankCardList(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/bankCard/list";
        post(context,url, params,callback);
    }


    public static void addBankCard(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/bankCard/add";
        post(context,url, params,callback);
    }
    public static void selectDriverSubscriptionList(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/driver/selectDriverSubscriptionList";
        post(context,url, params,callback);
    }

    public static void deleteDsByDriverAndShipper(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/driver/deleteDsByDriverAndShipper";
        post(context,url, params,callback);
    }
    public static void selectShipperSubscriptionList(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/driver/selectShipperSubscriptionList";
        post(context,url, params,callback);
    }

    public static void uploadDriverImg(Context context,File file,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/driver/uploadDriverImg";
        postFile(context,url, file,callback);
    }

    public static void addLines(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/driverline/add";
        post(context,url, params,callback);
    }

    public static void upDataLines(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/driverline/update";
        post(context,url, params,callback);
    }

    public static void addCarInfo(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/driver/add";
        post(context,url, params,callback);
    }

    public static void createFleet(Context context, EditCarTeamData editCarTeamData,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/fleet/add";
        postJsonBean(context,url, editCarTeamData,callback);

    }

    public static void selectFleetList(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/fleet/selectFleetList";
        post(context,url, params,callback);
    }

    public static void driveradd(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/fleet/Driveradd";
        post(context,url, params,callback);
    }
    public static void getByDriverOrFleet(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/evalute/getByDriverOrFleet";
        post(context,url, params,callback);
    }
    public static void selectFleetInfo(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/driver/selectFleetInfo";
        post(context,url, params,callback);
    }
    public static void updateFleetDriver(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/fleet/updateFleetDriver";
        post(context,url, params,callback);
    }
    public static void deleteFleet(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/fleet/deleteFleet";
        post(context,url, params,callback);
    }
    public static void selectFleetDriver(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/fleet/selectFleetDriver";
        post(context,url, params,callback);
    }

    public static void getHistoryOrder(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/driverOrder/historyOrder";
        post(context,url, params,callback);
    }
    public static void selectByOrderId(Context context,Map<String, Object> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/waybill/selectByOrderId";
        post(context,url, params,callback);
    }
    public static void selectByWaybillId(Context context,Map<String, Object> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/waybill/selectByWaybillId";
        post(context,url, params,callback);
    }

    public static void deleteWaybill(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/waybill/selectByWaybillId";
        post(context,url, params,callback);
    }
    public static void getForZHJ(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/waybill/getForZHJ";
        post(context,url, params,callback);
    }
    public static void updateWaybillByLibraryId(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/waybill/updateWaybillByLibraryId";
        post(context,url, params,callback);
    }
    public static void historyWayBill(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/driverOrder/historyWayBill";
        post(context,url, params,callback);
    }
    public static void selectWaybillMsg(Context context,Map<String, Object> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/driverOrder/selectWaybillMsg";
        post(context,url, params,callback);
    }
    public static void selectShipperMsg(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/driver/selectShipperMsg";
        post(context,url, params,callback);
    }
    public static void addDriverSubscription(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/driver/addDriverSubscription";
        post(context,url, params,callback);
    }

    public static void selectOrderMsgById(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/driverOrder/selectOrderMsgById";
        post(context,url, params,callback);
    }
    public static void receiveOrder(Context context,Map<String, Object> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/match/addmatch";
        post(context,url, params,callback);
    }
    public static void deletePendOrder(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/match/deletePendOrder";
        post(context,url, params,callback);
    }
    public static void startTranslate(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/waybill/start";
        post(context,url, params,callback);
    }
    public static void GetCarCurrentStatusByCarID(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/GPS/GetCarCurrentStatusByCarID";
        post(context,url, params,callback);
    }
    public static void selectOrderAddress(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/driverOrder/selectOrderAddress";
        post(context,url, params,callback);
    }
    public static void updateWaybillUnload(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/driverOrder/updateWaybillUnload";
        post(context,url, params,callback);
    }
    public static void updateWaybillUnload(Context context,ArrayList<File> files,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/driverOrder/updateWaybillUnload";
        postFiles(context,url,files, params,callback);
    }

    public static void uploadWaybillImagess(Context context,ArrayList<File> files,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/driverOrder/uploadWaybillImagess";
        postFiles(context,url,files, params,callback);
    }

    public static void updateWaybillStatus(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/driverOrder/updateWaybillStatus";
        post(context,url, params,callback);
    }


    public static void updateOrderUnload(Context context, ArrayList<File> files,Map<String, String> params, MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/driverOrder/updateOrderUnload";
        postFiles(context, url, files, params, callback);
       /* if (files!=null && files.size()>0) {
            postFiles(context, url, files, params, callback);
        }else {
            post(context,url, params,callback);
        }*/
    }
    public static void getSureValidateCode(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/driverOrder/getUnloadValidateCode";
        post(context,url, params,callback);
    }

    public static void bidOrder(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/bid/bidOrder";
        post(context,url, params,callback);
    }
    public static void selectDriverPendingOrder(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/bid/selectDriverPendOrder";
        post(context,url, params,callback);
    }
    public static void selectAdvancedOrderBydriver(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/AdvancedOrder/selectAdvancedOrderBydriver";
        post(context,url, params,callback);
    }
    public static void deleteAdvancedDriver(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/AdvancedOrder/deleteAdvancedDriver";
        post(context,url, params,callback);
    }
    public static void selectAdvancedDriverById(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/AdvancedOrder/selectAdvancedDriverById";
        post(context,url, params,callback);
    }
    public static void updateAdvancedDriver(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/AdvancedOrder/updateAdvancedDriver";
        post(context,url, params,callback);
    }
    public static void addBid(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/bid/addBid";
        post(context,url, params,callback);
    }
    public static void selectdriverOrder(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/driverOrder/selectdriverOrder";
        post(context,url, params,callback);
    }
    public static void updateOrderStatusByWaybill(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/driverOrder/updateOrderStatusByWaybill";
        post(context,url, params,callback);
    }
    public static void getLoadUnloadGuideInfo(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/wizard/get";
        post(context,url, params,callback);
    }
    public static void selWebWaybillWizard(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/wizardLine/selWebWaybillWizard";
        post(context,url, params,callback);
    }

    public static void AllotWaybill(Context context, Waybill waybill, MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/driverOrder/addAllotWaybill";
        postJsonBean(context,url, waybill,callback);
    }

    public static void GetCarCurrentStatusByOrderId(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/GPS/GetCarCurrentStatusByOrderId";
        post(context,url, params,callback);
    }
    public static void selectDriverWayBillList(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/driverOrder/DriverWayBillList";
        post(context,url, params,callback);
    }


    public static void getCarCurrentLocation(Context context,Map<String, String> params,MyStringCallback callback) {
        String url = "http://121.37.17.177:27012/api/GetCarCurrentStatusByCarID";
        postString(context,url, params,callback);
    }

    public static void getLoadUnloadGuideState(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/waybillWizard/get";
        post(context,url, params,callback);
    }
    public static void selectDriverInfo(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/driver/selectDriverInfo";
        post(context,url, params,callback);
    }
    public static void selectDriverInfo2(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/driver/selectDriverInfo";
        post(context,url, params,callback);
    }
    public static void updatePwdByVCode(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/user/updatePwdByVCode";
        post(context,url, params,callback);
    }
    public static void checkOrderStatus(Context context,Map<String, String> params, MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/order/getOrderStateChangeInfo";
        post(context,url, params, callback);
    }

    public static void checkWaybilStatus(Context context,Map<String, String> params, MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/waybill/getWayBillStateChangeInfo";
        post(context,url, params, callback);
    }

    //2.0改版接口
    public static void getOrderList(Context context,Map<String, Object> params, MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/driverOrder/getOrderInfo";
//        String url = ConstUtil.BASE_HOST_URL +  "info/driverOrder/selectdriverOrder";
        post(context,url, params,callback);
    }
    public static void getOrderCountInfo(Context context,Map<String, Object> params, MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/driverOrder/getOrderCountInfo";
//        String url = ConstUtil.BASE_HOST_URL +  "info/driverOrder/selectdriverOrder";
        post(context,url, params,callback);
    }

    public static void getDispatchOrder(Context context,Map<String, Object> params, MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/order/getDispatchInfoByFleetId";
//        String url = ConstUtil.BASE_HOST_URL +  "info/driverOrder/selectdriverOrder";
        post(context,url, params,callback);
    }


    public static void orderShelve(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/orderOperate/orderShelve";
        post(context,url, params,callback);
    }

    public static void waitTrans(Context context,Map<String, Object> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/driverOrder/DriverWayBillList2";
        post(context,url, params,callback);
    }

    public static void waitTransTopInfo(Context context,Map<String, Object> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/driverOrder/getDriverWayBillList2Count";
        post(context,url, params,callback);
    }
    public static void waybilList(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/order/getOrderWaybillByOrderId";
        post(context,url, params,callback);
    }
//重新竞价
    public static void reBid(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/bid/reBid";
        post(context,url, params,callback);
    }

    public static void moneyFollow(Context context, Map<String, Object> params, MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/driverOrder/getDriverCollectionInfoByDriverId";
        post(context,url, params,callback);
    }
    public static void deletWaybil(Context context, Map<String, Object> params, MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/waybill/fleetNoOrYes";
        post(context,url, params,callback);
    }

    public static void getDispatchInfoByOrderId(Context context, Map<String, Object> params, MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/order/getDispatchInfoByOrderId";
        post(context,url, params,callback);
    }

    public static void applyNoWaybill(Context context,Map<String, Object> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/waybill/applyNoWaybill";
        post(context,url, params,callback);
    }

    public static void selectWaybillInfo(Context context,Map<String, Object> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/waybill/selectWaybillInfo";
        post(context,url, params,callback);
    }



    public static void selectMessageList(Context context,Map<String, String> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/pushMessage/selectMessageListByPaging";
        post(context,url, params,callback);
    }
       public static void getWaybillInfoByWaybillId(Context context, Map<String, Object> params, MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "/info/waybill/getWaybillInfoByWaybillId";
        post(context,url, params,callback);
    }
    public static void insertPositionInfo(Context context, Map<String, Object> params, MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "/info/driver/insertPositionInfo";
        post(context,url, params,callback);
    }
    public static void signoff(Context context, Map<String, Object> params, MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/order/signoff";
        post(context,url, params,callback);
    }

    public static void validateCode(Context context,Map<String, Object> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "/info/user/validateCode";
        post(context,url, params,callback);
    }
    public static void deleteWaybillImgById(Context context,Map<String, Object> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "/info/driverOrder/deleteWaybillImgById";
        post(context,url, params,callback);
    }

    //加盟：
    public static void selectApplyInfo(Context context,Map<String, Object> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/business/selectApplyInfo";
        post(context,url, params,callback);
    }
    public static void updateIsVisible(Context context,Map<String, Object> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/business/updateIsVisible";
        post(context,url, params,callback);
    }
    public static void acceptBusinessRelation(Context context,Map<String, Object> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/business/acceptBusinessRelation";
        post(context,url, params,callback);
    }
    public static void refuseBusinessRelationship(Context context,Map<String, Object> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/business/refuseBusinessRelationship";
        post(context,url, params,callback);
    }
    public static void addBusinessRelation(Context context,Map<String, Object> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/business/getSearchBusiness";
        post(context,url, params,callback);
    }
    public static void selectRecommendBusiness(Context context,Map<String, Object> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/business/selectRecommendBusiness";
        post(context,url, params,callback);
    }
    public static void selectBusinessByDriverInfo(Context context,Map<String, Object> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/business/selectBusinessByDriverInfo";
        post(context,url, params,callback);
    }
    public static void getBusinessToJoin(Context context,Map<String, Object> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/business/getBusinessToJoin";
        post(context,url, params,callback);
    }
    public static void selectBusinessByFleet(Context context,Map<String, Object> params,MyCallback callback) {
        String url = ConstUtil.BASE_HOST_URL + "info/business/selectBusinessByFleet";
        post(context,url, params,callback);
    }

    public static void postString(Context context, String url,Map<String, String> params,MyStringCallback callback)
    {
        OkHttpUtils
                .postString()
                .url(url)
                .tag(context)
                .mediaType(MediaType.parse("application/json; charset=utf-8"))
                .content(JsonUtil.parseMapToJson(params))
                .build()
                .execute(callback);
    }

    private static void postJsonBean(Context context, String url, Object obj, MyCallback callback) {
        OkHttpUtils
                .postString()
                .url(url)//
                .mediaType(MediaType.parse("application/json; charset=utf-8"))
                .content(JsonUtil.parseBeanToJson(obj))
                .addHeader("token", SharedPrefUtil.getToken())
                .addHeader("userId", SharedPrefUtil.getUserId())
                .tag(context)
                .build()//
                .execute( callback);
    }


    public static void post(Context context,String url, Map<String, ? extends Object> params, final MyCallback callback) {
        if(!NetUtil.checkNetworkIfAvailable(context)){
            EventBus.getDefault().post( new ErrorEvent(ConstUtil.HTTP_NET_ERROR,"请打开网络", context, context));
            return;
        }
        OkHttpUtils
                .postString()
                .url(url)//
                .mediaType(MediaType.parse("application/json; charset=utf-8"))
                .content(JsonUtil.parseMapToJson(params))
                .addHeader("token", SharedPrefUtil.getToken())
                .addHeader("userId", SharedPrefUtil.getUserId())
                .tag(context)
                .build()//
                .execute( callback);
    }


    public static void get(Context context,String url, Map<String, String> params, final MyCallback callback) {
        if(!NetUtil.checkNetworkIfAvailable(context)){
            EventBus.getDefault().post( new ErrorEvent(ConstUtil.HTTP_NET_ERROR,"请打开网络", context, context));
            return;
        }
        OkHttpUtils
                .get()//
                .url(url)//
                .params(params)
                .tag(context)
                .build()//
                .execute(callback);
    }



    public static void postFile(Context context,String url, File file,MyCallback callback) {
        if(!NetUtil.checkNetworkIfAvailable(context)){
            EventBus.getDefault().post( new ErrorEvent(ConstUtil.HTTP_NET_ERROR,"请打开网络", context, context));
            return;
        }
        if (!file.exists())
        {
            PrintUtil.toast(context, "文件不存在，请修改文件路径");
            return;
        }

        Map<String, String> params = new HashMap<>();
        params.put("token", SharedPrefUtil.getToken());
        params.put("userId", SharedPrefUtil.getUserId());

        Map<String, String> headers = new HashMap<>();
        headers.put("token", SharedPrefUtil.getToken());
        headers.put("userId", SharedPrefUtil.getUserId());
        OkHttpUtils.post()//
                .tag(context)
                .addFile("image", file.getName(), file)//
                .url(url)//
                .params(params)//
                .headers(headers)//
                .build()//
                .execute(callback);
    }

    public static void postFiles(Context context,String url,ArrayList<File> files,Map<String, String> params,MyCallback callback) {
        if(!NetUtil.checkNetworkIfAvailable(context)){
            EventBus.getDefault().post( new ErrorEvent(ConstUtil.HTTP_NET_ERROR,"请打开网络", context, context));
            return;
        }
        Map<String,File> fileMap=new HashMap<String,File>();
        if (files.size()>0){
            for (File file : files){
                fileMap.put(file.getName(),file);
            }
        }
        Map<String, String> headers = new HashMap<>();
        headers.put("token", SharedPrefUtil.getToken());
        headers.put("userId", SharedPrefUtil.getUserId());
        OkHttpUtils.post()//
                .tag(context)
                .files("images",fileMap)
                .url(url)//
                .params(params)//
                .headers(headers)//
                .build()//
                .execute(callback);
    }


    public static void cancelCall(Context context){
        OkHttpUtils.getInstance().cancelTag(context);
    }
}